import pathlib
import time
import re
import typing
import os
import yaml
import ctypes
import psutil
import subprocess
import requests
import winsound
import datetime
import rich
from selenium.webdriver.edge.webdriver import WebDriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.common.exceptions import *










def On_InputPage_InputService(driver:WebDriver,wait:WebDriverWait,actions:ActionChains):
    
    # 1.展开服务与履约
    try:
        element = wait.until(expected_conditions.presence_of_element_located((By.XPATH,f"//div[contains(@id,'服务与履约')]//*[text()='展开更多']")))
        driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'});",element)
        try:
            element.click()
        except (ElementClickInterceptedException,ElementNotInteractableException):
            driver.execute_script("arguments[0].click();",element)
    except TimeoutException:
        print(f"提示 : 无法对 [服务与履约] 进行展开操作!\n可能是已经展开过了!")
    
    # 2.填写购买限制
    try:
        element = wait.until(expected_conditions.visibility_of_element_located((By.XPATH,"//input[contains(@dropdownclassname,'每个订单最多购买')]")))
        driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'});",element)
        while element.get_attribute("value"):
            element.send_keys(Keys.BACKSPACE*20)
        element.send_keys("3")
    except TimeoutException:
        print(f"提示: 没有找到 [每个订单最多购买] 输入框元素!")
    
    try:
        element = wait.until(expected_conditions.visibility_of_element_located((By.XPATH,"//input[contains(@dropdownclassname,'每个用户累计可购买')]")))
        driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'});",element)
        while element.get_attribute("value"):
            element.send_keys(Keys.BACKSPACE*20)
        element.send_keys("3")
    except TimeoutException:
        print(f"提示: 没有找到 [每个用户累计可购买] 输入框元素!")